package com.gexiaobao.pigeon.ui.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.gexiaobao.pigeon.R
import com.gexiaobao.pigeon.app.model.bean.TrainingListResponse
import com.gexiaobao.pigeon.app.util.Util

/**
 * @author:hxw
 * @date  :2023/1/5
 * @desc  :
 */
class MyTrainingListAdapter(data: ArrayList<TrainingListResponse.InfoList>) :
    BaseQuickAdapter<TrainingListResponse.InfoList, BaseViewHolder>(R.layout.item_training_list, data) {

    override fun convert(holder: BaseViewHolder, item: TrainingListResponse.InfoList) {
        item.run {
            holder.setText(
                R.id.tv_item_training_time,
                if (item.liberateTime.isEmpty()) "" else context.getString(R.string.item_train_fly_main_list_time) + item.liberateTime
            )
            holder.setText(R.id.tv_item_training_address, if (item.address.isEmpty()) "" else context.getString(R.string.place) + item.address)
            holder.setText(
                R.id.tv_item_training_distance,
                if (item.distance.isEmpty()) "" else context.getString(R.string.Ullage) + "${Util.distanceMath("" + item.distance)}" + context.getString(
                    R.string.kilometre
                )
            )

            var isGPS = false
            var iconDraw = R.mipmap.weikaishi_xunfang_my_
            var textColor = R.color.color_8F8F8F
            var text = context.getString(R.string.item_train_fly_main_list_not_start)//"未开始"
            when (item.trainingStatus) {
                1 -> {
                    text = context.getString(R.string.item_train_fly_main_list_not_start)//"未开始"
                    textColor = R.color.colorAccent
                    iconDraw = R.mipmap.weikaishi_xunfang_my_
                    isGPS = true
                }

                2 -> {
                    text = context.getString(R.string.train_fly_detail_detail_fragment_not_started)//"已开始"
                    textColor = R.color.color_4CAF50
                    iconDraw = R.mipmap.yikaishi_xunfang_my_
                    isGPS = true
                }

                3 -> {
                    text = context.getString(R.string.finished)//"已结束"
                    textColor = R.color.color_8F8F8F
                    iconDraw = R.mipmap.yijieshu_xunfang_my_
                    isGPS = false
                }
            }
//            holder.setGone(R.id.tvGps, isGPS)
            holder.setText(R.id.train_fly_main_list_item_status, text)
            holder.setBackgroundResource(R.id.train_fly_main_list_item_icon, iconDraw)
            holder.setTextColor(R.id.train_fly_main_list_item_status, context.resources.getColor(textColor))
        }
    }
}